package com.stars.empoly.utils

import android.content.Context
import com.qmuiteam.qmui.skin.QMUISkinManager
import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet.BottomListSheetBuilder
import com.stars.empoly.inte.ChoiceData
import com.stars.empoly.inte.ChoiceListData
import com.stars.empoly.inte.ChoseData
import com.stars.empoly.model.InsurancePlan
import com.stars.empoly.model.SelectData
import java.util.ArrayList


/**
 *
 *on 2020/10/13
 */
object PopuBottomUtils {

     fun showList(context: Context,
                  list: ArrayList<SelectData>, chose: ChoiceListData
    ) {
        val builder = BottomListSheetBuilder(context)
        builder.setGravityCenter(true)
                .setSkinManager(QMUISkinManager.defaultInstance(context))
                .setTitle("请选择")
                .setAddCancelBtn(true)
                .setAllowDrag(false)
                .setNeedRightMark(false)
                .setOnSheetItemClickListener { dialog, itemView, position, tag ->
                    chose?.onRestuse(list[position].code,list[position].name)
                    dialog.dismiss()
                }

        for (item in list) {
            builder.addItem(item.name)
        }
        builder.build().show()
    }



    fun showListString(context: Context,
                 list: ArrayList<String>, chose: ChoiceData
    ) {
        val builder = BottomListSheetBuilder(context)
        builder.setGravityCenter(true)
                .setSkinManager(QMUISkinManager.defaultInstance(context))
                .setTitle("请选择")
                .setAddCancelBtn(true)
                .setAllowDrag(false)
                .setNeedRightMark(false)
                .setOnSheetItemClickListener { dialog, itemView, position, tag ->
                    chose?.onRestuse(list[position])
                    dialog.dismiss()
                }

        for (item in list) {
            builder.addItem(item)
        }
        builder.build().show()
    }



    fun showListChose(context: Context,
                       list: List<InsurancePlan>, chose: ChoseData
    ) {

        var data = ArrayList<String>()
        for (item in list) {
            data.add(item.schemeName)
        }

        val builder = BottomListSheetBuilder(context)
        builder.setGravityCenter(true)
                .setSkinManager(QMUISkinManager.defaultInstance(context))
                .setTitle("请选择")
                .setAddCancelBtn(true)
                .setAllowDrag(false)
                .setNeedRightMark(false)
                .setOnSheetItemClickListener { dialog, itemView, position, tag ->
                    chose?.onRestuse(list[position])
                    dialog.dismiss()
                }

        for (item in data) {
            builder.addItem(item)
        }
        builder.build().show()
    }



}
